package com.smartian.v2.model;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import java.io.Serializable;

/**
 * Created by tianweitong on 2020/3/13.
 */

public class DateTimeNode implements Comparable<DateTimeNode>, Serializable {

    public final static int TYPE_DATE = 0;
    public final static int TYPE_TIME = 1;
    public final static int TYPE_LOCATOR = 3;
    public String text;
    public int index;
    public String resultText;
    public int type = TYPE_DATE;
    public String locatorText;

    @Override
    public String toString() {
        return "DateTimeNode{" +
                "text='" + text + '\'' +
                ", index=" + index +
                ", resultText='" + resultText + '\'' +
                ", type=" + type +
                ", locatorText='" + locatorText + '\'' +
                '}';
    }

    @Override
    public int compareTo(@NonNull DateTimeNode o) {

        if (!(o instanceof DateTimeNode)) return Integer.MIN_VALUE;
        /**
         * 可信度排名规则
         * 1、日期时间出现的索引位置
         * 2、结果是否为空
         * 3、有无locator决定上下午，晚上，凌晨
         * 4、匹配区域的长度
         */
        int dx = this.index - o.index;
        if (dx != 0) return dx;

        if (TextUtils.isEmpty(o.resultText) && TextUtils.isEmpty(o.resultText)) return 0;
        if (o.resultText != null && this.resultText == null) return -1;
        if (o.resultText == null && this.resultText != null) return 1;
        if (TextUtils.isEmpty(o.locatorText) && TextUtils.isEmpty(o.locatorText)) return 0;
        if (o.locatorText != null && this.locatorText == null) return -1;
        if (o.locatorText == null && this.locatorText != null) return 1;
        if (TextUtils.isEmpty(o.text) && TextUtils.isEmpty(text)) return 0;
        if (o.text != null && this.text == null) return -1;
        if (o.text == null && this.text != null) return 1;

        return this.text.length() - o.text.length();

    }
}
